/*
 * @Descripttion:  
 * @version:  
 * @Author: chenxf
 * @Date: 2022-08-04 10:18:18
 */
import { getAction, putAction, postAction } from '@/api/manage'
import { serviceApi } from '@/api/common.js'

export const api = {
  list: serviceApi.category + '/categories', // 获取根列表数据
  delete: (ids) => `${serviceApi.category}/categories/${ids}`,
  deleteBatch: serviceApi.category + '/categories/delete-batch',
  add: serviceApi.category + '/categories',
  edit: serviceApi.category + '/categories',
  checkCode: serviceApi.category + '/categories/code-check',
  addCategoryRule: serviceApi.category + '/categories/rules',
  editCategoryRule: serviceApi.category + '/categories/rules'
}

/**
 * 添加分类
 * @param parameter
 * @returns {*}
 */
 export const addCategory = params => postAction(api.add, params);

 /**
 * 编辑分类
 * @param parameter
 * @returns {*}
 */
export const editCategory = params => putAction(api.edit, params);

/**
 * 获取根分类数据
 * @param parameter
 * @returns {*}
 */
export const getCategoryRootList = params => getAction(api.list, params);

/**
 * 获取子分类数据
 * @param {*} params
 * @returns
 */
export const getCategoryChildList = (pid, params) => getAction(`${serviceApi.category}/categories/children/${pid}`, params);

/**
* 获取子分类数据
* @param {*} params
* @returns
*/
export const getCategoryChildListBatch = (params) => getAction(serviceApi.category + '/categories/children/batch', params);

/**
* 验证分类编码
* @param {*} params
* @returns
*/
export const categoryCheckCode = params => getAction(api.checkCode, params);

/**
 * 分类字典-通过Code获取节点数据
 * @param {*} code 分类编码
 * @param {*} params 参数
 * @returns 返回值
 */
 export const loadCategoryData = (code, params) => getAction(`${serviceApi.category}/categories/list-all/${code}`, params)

/**
 * 通过Code获取分类对象
 * @param {*} code 分类编码
 * @param {*} params 参数
 * @returns 返回值
 */
 export const queryByCode = (code, params) => getAction(`${serviceApi.category}/categories/code/${code}`, params)

/**
 * 通过ID获取父类编码规则
 * @param {*} id
 * @returns 返回值
 */
 export const queryParentRuleById = (id) => getAction(`${serviceApi.category}/categories/parent-rule/${id}`)

 /**
 * 添加/编辑规则配置
 * @param {*} params
 * @returns 返回值
 */
export const saveOrUpdateCategoryRule = (params) => postAction(api.addCategoryRule, params);
